const TILES_MAP = require("TileMap");

cc.Class({
    extends: cc.Component,

    properties: {
        tileAtlas : cc.SpriteAtlas,
        backAtlas : cc.SpriteAtlas,
        tiles : [cc.Node]
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
    },

    // use this for initialization
    onLoad: function () {
        this.type = null;
        this.MJId = null;
    },
    /**
     * 初始化一组牌
     * type {String} 牌的类型
     * MJId {String} 牌面
     * ConcealedKong {Boolean} 暗杠标识符，true为暗杠
     */
    init : function (type, MJId, ConcealedKong) {
        this.type = type;
        this.MJId = MJId;

        this.tiles[3].active = false;
        switch (type) {
            case "peng":
                for(var i in this.tiles){
                    this.tiles[i].getComponent(cc.Sprite).spriteFrame = this.tileAtlas.getSpriteFrame(TILES_MAP[MJId]);
                }
                break;
            case "gang":
                this.tiles[3].active = true;
                if(ConcealedKong){
                    for(var i in this.tiles){
                        this.tiles[i].getComponent(cc.Sprite).spriteFrame = this.backAtlas.getSpriteFrame("bottom_meld");
                    }
                    // this.tiles[3].getComponent(cc.Sprite).spriteFrame = this.tileAtlas.getSpriteFrame(TILES_MAP[MJId]);
                }else{
                    for(var i in this.tiles){
                        this.tiles[i].getComponent(cc.Sprite).spriteFrame = this.tileAtlas.getSpriteFrame(TILES_MAP[MJId]);
                    }
                }
                break;
            case "chi":
                for(var i in this.tiles){
                    this.tiles[i].getComponent(cc.Sprite).spriteFrame = this.tileAtlas.getSpriteFrame(TILES_MAP[MJId[i]]);
                }
                break;
        }
    },

    /**
     * 补杠
     */
    fillBar : function () {
        this.tiles[3].active = true;
    }
});